﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace LibYanu.Security.Validation
{
    public class RoleValidation:ValidationAttribute
    {
        public string[] PropertyNames { get; private set; }
        public int MinLength { get; private set; }

        public RoleValidation(int minleng)
        {

            MinLength = minleng;
        }

        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            return new ValidationResult(this.FormatErrorMessage("dsfS" ));
            return null;
        }

        
        public override bool IsValid(object value)
        {
            if (value.ToString().Length < MinLength)
            {
                //throw new ValidationException("Kurangpanjang");
                return false;
            }
            return true;
        }
        //protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        //{
        //    var properties = this.PropertyNames.Select(validationContext.ObjectType.GetProperty);
        //    var values = properties.Select(p => p.GetValue(validationContext.ObjectInstance, null)).OfType<string>();
        //    var totalLength = values.Sum(x => x.Length) + Convert.ToString(value).Length;
        //    if (totalLength < this.MinLength)
        //    {
        //        return new ValidationResult(this.FormatErrorMessage(validationContext.DisplayName));
        //    }
        //    return null;
            
        //}

    }
}
